/*
 *  $Id: Enchantment.cs 1060 2010-05-20 12:34:55Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima {
    /// <summary>
    /// Абстрактный эффект чар, хранящий соответствующую карту и возвращающий ее в колоду
    /// </summary>
    public abstract class EnchantmentAffect: SpellAffect {
        private Player _caster;
        private EnchantmentCard _card;
        private bool _returnToHand;

        public EnchantmentAffect() : this(false) {
        }
        public EnchantmentAffect(bool def) : base(def) {
            _returnToHand = false;
        }

        public void SetData(Player caster, EnchantmentCard card) {
            _caster = caster;
            _card = card;
        }

        public override Card BaseCard {
            get { return _card; }
        }

        public EnchantmentCard Enchantment {
            get { return _card; }
        }

        public Player Caster {
            get { return _caster; }
            set { _caster = value; }
        }

        public void ReturnToHand() {
            _returnToHand = true;
        }

        public override Affect Clone() {
            EnchantmentAffect affect = (EnchantmentAffect) Activator.CreateInstance(GetType());
            affect.SetData(null, _card);
            return affect;
        }

        /// <summary>
        /// Возврат карты при снятии эффекта
        /// </summary>
        public override void OnRemove() {
            if (_caster != null && _card != null)
                _caster.CardPutTo(_card, _returnToHand ? CardPlace.Hands : CardPlace.Deck2);
        }
    }

    public abstract class EnchantmentAffect<T>: EnchantmentAffect where T: EnchantmentCard {
        public EnchantmentAffect(): base() {}
        public EnchantmentAffect(bool def): base(def) {}

        public override string Id {
            get { return AffectManager.GetCardId<T>(null); }
        }
    }

    /// <summary>
    /// Абстрактный эффект чар, сохраняемых в могильнике
    /// </summary>
    public abstract class GraveyardEnchantmentAffect: EnchantmentAffect {
        public GraveyardEnchantmentAffect(): base() {}
        public GraveyardEnchantmentAffect(bool def): base(def) {}
    }

    public abstract class GraveyardEnchantmentAffect<T>: GraveyardEnchantmentAffect where T: EnchantmentCard {
        public GraveyardEnchantmentAffect(): base() {}
        public GraveyardEnchantmentAffect(bool def): base(def) {}

        public override string Id {
            get { return AffectManager.GetCardId<T>(null); }
        }
    }
}
